<template>
  <el-container id="hello">
    <el-header class="hh">
      <div>
        <img src="../assets/heima.png" alt="" />
        <span class="ff">复仇者管理系统</span>
      </div>
      <el-button
        style="background-color: rgba(0, 0, 0, 0.5)"
        round
        @click="hanhan"
        >退出</el-button
      ></el-header
    >
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="iscollapse ? '64px' : '200PX'" class="ben">
        <div class="toggle-button" @click="toggle">|||</div>
        <!-- 侧边栏菜单区域 -->
        <el-menu
          background-color="rgba(0, 0, 0, 0.1)"
          text-color="#fff"
          active-text-color="purple"
          :unique-opened="true"
          :collapse="iscollapse"
          :collapse-transition="false"
          :router="true"
          default-active="val"
        >
          <!-- 一级菜单 -->
          <el-submenu :index="item.id + ''" v-for="item in men" :key="item.id">
            <template slot="title">
              <i :class="isbi[item.id]"></i>
              <span>{{ item.authName }}</span>
            </template>

            <!-- 二级菜单 -->
            <el-menu-item
              :index="'/' + subItem.path"
              v-for="subItem in item.children"
              :key="subItem.id"
              @click="tokeny('/' + subItem.path)"
            >
              <template slot="title">
                <i class="el-icon-delete-solid"></i>
                <span>{{ subItem.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main class="xixi">
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      men: [],
      isbi: {
        125: "iconfont icon-showpassword",
        103: "iconfont icon-showpassword",
        101: "iconfont icon-showpassword",
        102: "iconfont icon-showpassword",
        145: "iconfont icon-showpassword",
      },
      iscollapse: false,
      // 被激活的链接地址
      val: "",
    };
  },
  created() {
    this.getMenuList();
    // 获取path地址
    this.val = window.sessionStorage.getItem("val");
  },
  methods: {
    hanhan() {
      // 清空本地数据
      window.sessionStorage.clear();
      this.$router.push("/login");
      // location.href="http://baidu.com"
      this.$message({
        showClose: true, //是否显示关闭按钮
        message: "赛哟拉拉",
        center: true,
        duration: 800,
        type: "warning",
      });
    },
    async getMenuList() {
      const { data: res } = await this.$http.get("menus");
      console.log(res);
      if (res.meta.status !== 200) return this.$message.error("获取菜单错误");
      this.men = res.data;
    },
    toggle() {
      this.iscollapse = !this.iscollapse;
      // console.log(this);
    },
    tokeny(val) {
      window.sessionStorage.setItem("val", val);
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
#hello {
  height: 100%;
  .hh {
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    > div {
      display: flex;
      align-items: center;
    }
    .ff {
      margin-left: 15px;
      font-size: 20px;
      color: #fff;
    }
  }
  .ben {
    background-color: rgba(0, 0, 0, 0.5);
  }
  .xixi {
    background-color: #fff;
  }
  .iconfont {
    margin-right: 10px;
  }
  .toggle-button {
    background-color: rgba(0, 0, 0, 0.1);
    text-align: center;
    font-size: 10px;
    width: 100%;
    // height: 24px;
    line-height: 24px;
    color: #fff;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
  .el-menu {
    border-right: none;
  }
}
</style>
